import shutil
import os


def rename(path, despath):
    files = os.listdir(path)
    if os.path.exists(despath):
        shutil.rmtree(despath)
    else:
        os.mkdir(despath)
    for file in files:
        file_path = os.path.join(path, file)
        filepath, tempfilename = os.path.split(file_path)
        shotname, extension = os.path.splitext(tempfilename)
        name, label_type = shotname.split('.')
        new_name = name + '.xml'
        file_dest_path = os.path.join(despath, new_name)
        shutil.copy(file_path, file_dest_path)


if __name__ == '__main__':
    path = 'D:/BaiduNetdiskDownload/USC行人数据集/dataA/xml'
    destpath = 'D:/BaiduNetdiskDownload/USC行人数据集/dataA/xml_dst'
    rename(path, destpath)